package com.mini.cn.goods.servlet.ws;

import com.mini.cn.goods.io.netty.ws.WebSocketSession;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.

 * User: fly
 * Date: 2020-02-11
 * Time: 2:52 下午
 */


public enum WSApplicationData {

    INSTANCE;

    private final AtomicInteger activeSession;

    //用户id缓存
    private final Map<String, WebSocketSession> userSessionMap;//所有客户

    //推送缓存
    private final Map<String, String> responseCache;

    //register msgSceneId cache
    private final Map<String, String> msgSceneIdRegisterMap;

    //unregister msgSceneId cache
    private final Map<String, String> msgSceneIdUnRegisterMap;

    //VERIFY msgSceneId cache
    //private final Map<String, String> msgSceneIdVerifyMap;

    //根据消息缓存 ConcurrentLinkedQueue ==> ConcurrentHashMap
    private final Map<String, ConcurrentHashMap<WebSocketSession, Boolean>> registerMsgMap;

    WSApplicationData() {
        activeSession = new AtomicInteger();
        userSessionMap = new ConcurrentHashMap<String, WebSocketSession>(10000);
        responseCache = new CallMapCache<>(100);
        registerMsgMap = new ConcurrentHashMap<String, ConcurrentHashMap<WebSocketSession, Boolean>>(1000);
        msgSceneIdRegisterMap = new CallMapCache<>(100);
        msgSceneIdUnRegisterMap = new CallMapCache<>(100);
        //msgSceneIdVerifyMap = new CallMapCache<>(100);
    }

    public AtomicInteger getActiveSession() {
        return activeSession;
    }

    public Map<String, WebSocketSession> getUserSessionMap() {
        return userSessionMap;
    }

    public Map<String, ConcurrentHashMap<WebSocketSession, Boolean>> getRegisterMsgMap() {
        return registerMsgMap;
    }

    public Map<String, String> getResponseCache() {
        return responseCache;
    }

    public Map<String, String> getMsgSceneIdRegisterMap() {
        return msgSceneIdRegisterMap;
    }

    public Map<String, String> getMsgSceneIdUnRegisterMap() {
        return msgSceneIdUnRegisterMap;
    }

//    public Map<String, String> getMsgSceneIdVerifyMap() {
//        return msgSceneIdVerifyMap;
//    }
}
